package common

import "github.com/gin-gonic/gin"

var (
	Success = 1
	Fail    = 0
)

type Response struct {
	Code    int         `json:"code"`
	Message string      `json:"message"`
	Data    interface{} `json:"data"`
	ErrMsg  string      `json:"errMsg"`
}

func SuccessWithMessage(msg string, ctx *gin.Context) {
	var response = Response{
		Code:    Success,
		Message: msg,
		Data:    nil,
		ErrMsg:  "",
	}
	ctx.JSON(200, response)
}

func SuccessWithData(data interface{}, ctx *gin.Context) {
	response := Response{
		Code:    Success,
		Message: "",
		Data:    data,
		ErrMsg:  "",
	}
	ctx.JSON(200, response)
}

func FailWithErr(err error, ctx *gin.Context) {
	response := Response{
		Code:    Fail,
		Message: "",
		Data:    nil,
		ErrMsg:  err.Error(),
	}
	ctx.JSON(200, response)
}

func FailWithMessage(msg string, ctx *gin.Context) {
	response := Response{
		Code:    Fail,
		Message: msg,
		Data:    nil,
		ErrMsg:  "",
	}
	ctx.JSON(200, response)
}
